#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const LL MAXN=10000007;
LL base[]={1814400,181440,20160,2520,360,60,12,3,1};//9,8,7,6,5,4,3,2,1
char ch[]="987654321";
string res(int t) {
	bool flag=false;
	if (t%2==1) flag=true, t-=1;
	string x="";
	for (int j=0; j<9; ++j) {
		int len=t/base[j];
		for (int k=0; k<len; ++k) {
			x=x+ch[j];
		}
		t=t%base[j];
	}
	if (flag) x+='0';
	return x;
}
int main() {
	int T,ask;
	cin>>T;
	while (T--) {
		scanf("%d", &ask);
		cout<<res(ask)<<endl;
	}
	return 0;
}
